package com.yonyou.pmclouds.billview.config;

import com.yonyou.pmclouds.billview.plugin.IBillViewCustomPlugin;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BillViewPluginConfig implements BeanPostProcessor {

    private BillViewPluginFactory billViewPluginFactory = new BillViewPluginFactory();
    @Bean
    public BillViewPluginFactory billViewPluginFactory() {
        return billViewPluginFactory;
    }


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        if(bean instanceof IBillViewCustomPlugin){
            billViewPluginFactory.addBuziService(((IBillViewCustomPlugin)bean).getBillType(),((IBillViewCustomPlugin)bean));
        }

        return bean;
    }
}
